package com.bnzj.cloud.business.core.persistence.entity;

import com.bnzj.core.persistence.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import java.util.List;

@Getter
@Setter
@ToString(exclude = "childDeptList", callSuper = true)
@Entity
@Table(name = "bnz_sys_department")
@Schema(description="部门")
public class SysDepartment extends BaseEntity {
    private static final long serialVersionUID = -3954548195710565977L;
    @Schema(description="父部门ID")
    private Long pid;// 父ID
    @Schema(description="部门名称")
    private String name;// 部门名称
    @Schema(description="部门编码")
    private String code;// 部门编码
    @Schema(description="排序依据")
    private Short sequence;// 排序依据
    @Schema(description="路径索引")
    private String pathIndex;// 路径索引
    @Schema(description="启用状态")
    private Boolean enabled;// 启用状态
    @Schema(description="部门全称")
    private String fullName;
    @Schema(description="是否存在下级")
    @Transient
    private Long childNum;
    
    @OneToMany(mappedBy = "pid", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
    @JsonIgnore
    private List<SysDepartment> childDeptList;

    private static SysDepartment root = new SysDepartment();
    
    static {
        root.setId(0L);
        root.setName("公司");
    }
    
    public static SysDepartment getRoot() {
        return root;
    }
}
